#include "MPC5604B_0M27V_0102.h"
#include "main.h"





void StartUpCheck(void)
{
  vuint32_t x = 0;
  	
  PA2_PWM_SERVO = 1500;
  LED1=1;  LED2=1;  LED3=1;  LED4=1;   for(x=0;x<=1600000;x++);
  LED1=0;  LED2=0;  LED3=0;  LED4=0;   for(x=0;x<=1600000;x++);
  PA2_PWM_SERVO = 2180;
  LED1=1;  LED2=1;  LED3=1;  LED4=1;   for(x=0;x<=1600000;x++);    ///   LED=0 prendido      LED=1 apagado
  LED1=0;  LED2=0;  LED3=0;  LED4=0;   for(x=0;x<=1600000;x++);
  PA2_PWM_SERVO = 1850;
  LED1=1;  LED2=1;  LED3=1;  LED4=1;   for(x=0;x<=1600000;x++);
  LED1=0;  LED2=0;  LED3=0;  LED4=0;   for(x=0;x<=1600000;x++);
  LED1=1;  LED2=1;  LED3=1;  LED4=1;   for(x=0;x<=800000;x++);
  LED1=0;  LED2=0;  LED3=0;  LED4=0;   for(x=0;x<=800000;x++); 
  LED1=1;  LED2=1;  LED3=1;  LED4=1;   for(x=0;x<=800000;x++); 
  LED1=0;  LED2=0;  LED3=0;  LED4=0;   for(x=0;x<=800000;x++); 
  LED1=1;  LED2=1;  LED3=1;  LED4=1; 	
  
}

void FindVertSync(vuint32_t syn_hoz)  //  sync veritacl entre .18mv/37adc  y .28mv/57adc
{
  vuint32_t b_syn_vt   = 1;       
  vuint32_t syn_vid[15] = {0};
          
  
  while(b_syn_vt)      ///  busca sync vertical y configura emios0ch16 a contar 15mseg, se ejecuta solo 1 vez
  {
    syn_vid[0] = syn_vid[1];
    syn_vid[1] = syn_vid[2];
    syn_vid[2] = syn_vid[3];
    syn_vid[3] = syn_vid[4];
    syn_vid[4] = syn_vid[5];
    syn_vid[5] = syn_vid[6];
    syn_vid[6] = syn_vid[7];
    syn_vid[7] = syn_vid[8];
    syn_vid[8] = syn_vid[9];
    syn_vid[9] = syn_vid[10];
    syn_vid[10] = syn_vid[11];
    syn_vid[11] = syn_vid[12];
    syn_vid[12] = PB4_read_adc_0; 
              
    if( (syn_vid[0]<=syn_hoz) && (syn_vid[1]<=syn_hoz) && (syn_vid[2]<=syn_hoz) && (syn_vid[3]<=syn_hoz) && (syn_vid[4]<=syn_hoz) &&
        (syn_vid[5]<=syn_hoz) && (syn_vid[6]<=syn_hoz) && (syn_vid[7]<=syn_hoz) && (syn_vid[8]<=syn_hoz) && (syn_vid[9]<=syn_hoz) &&
        (syn_vid[10]<=syn_hoz) && (syn_vid[11]<=syn_hoz) && (syn_vid[12]<=syn_hoz)  )  
    {
       //emios0_ch16_init(14999, 2);
       b_syn_vt = 0;          
    } 
        
  }
	
	
}